package cn.sdormitory.controller.smartdor;

import cn.sdormitory.basedata.vo.BStudentListVo;
import cn.sdormitory.common.api.CommonPage;
import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.smartdor.entity.SdDeptUnClockCount;
import cn.sdormitory.smartdor.entity.SdNormalAttence;
import cn.sdormitory.smartdor.service.SdNormalAttenceService;
import cn.sdormitory.smartdor.vo.SdNormalAttenceQueryVo;
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @className: SdNormalAttenceController  获取所有考勤数据
 * @author: Alex
 * @date: 2024/9/11
 **/
@RestController
@RequestMapping("/smartdor/normalSdAttence")
public class SdNormalAttenceController {
	
	@Resource
	private SdNormalAttenceService sdNormalAttenceService;
	
	@PostMapping("/getList")
	public CommonResult<CommonPage<SdNormalAttence>> getNormalSdAttenceList(@RequestBody SdNormalAttenceQueryVo sdNormalAttenceQueryVo) {
		IPage<SdNormalAttence> page = sdNormalAttenceService.getSdAttenceList(sdNormalAttenceQueryVo);
		
		return CommonResult.success(CommonPage.restPage(page));
	}
	
	@PostMapping("/getWeekendAttenceList")
	public CommonResult<CommonPage<SdNormalAttence>> getWeekendAttenceList(@RequestBody SdNormalAttenceQueryVo sdNormalAttenceQueryVo) {
		IPage<SdNormalAttence> page = sdNormalAttenceService.getWeekendAttenceList(sdNormalAttenceQueryVo);
		
		return CommonResult.success(CommonPage.restPage(page));
	}
	
	/**
	 * 根据日期获取部门下面未打卡学生数量统计
	 * @author alex
	 * @date 2024/10/15 9:54
	 * @return
	 */
	@ApiOperation("getUnClockStuCountByDate =》 根据日期获取部门下面晚寝未打卡的学生数量")
	@GetMapping("/getUnClockStuCountByDate")
	public CommonResult<List<SdDeptUnClockCount>> getUnClockStuCountByDate(String checkDate) {
		List<SdDeptUnClockCount> sdDeptUnClockCounts = sdNormalAttenceService.getUnClockStuCountByDate(checkDate);
		return CommonResult.success(sdDeptUnClockCounts);
	}
	
	@ApiOperation("getUnClockStuListByDeptId =》 根据日期获取部门下面晚寝未打卡的学生列表")
	@GetMapping("/getUnClockStuListByDeptId")
	public CommonResult<List<BStudentListVo>> getUnClockStuListByDeptId(String deptId, String checkDate) {
		List<BStudentListVo> sdDeptUnClockCounts = sdNormalAttenceService.getUnClockStuListByDeptId(deptId, checkDate);
		return CommonResult.success(sdDeptUnClockCounts);
	}
	
	
	@ApiOperation("导出学生信息")
	@GetMapping("/excel/exportStudent")
	public void importStudent(HttpServletResponse response,String deptId, String checkDate) throws IOException {
		//查询学生信息
		List<BStudentListVo> studentInfoExcels = sdNormalAttenceService.getUnClockStuListByDeptId(deptId, checkDate);
		EasyExcel.write(response.getOutputStream(), BStudentListVo.class).sheet("学生信息").doWrite(studentInfoExcels);
	}
}
